﻿/* *****************************************************************************
 * @ Encoding: UTF-8
 * @ File Name: naughty_differential_node_var.cpp
 * @ Author: carl
 * @ Email: naughtygeng@qq.com
 * @ Created Time: 2022-7月-06(星期三) 21:09:22
 * @ All Rights Reserved
 * *****************************************************************************/

#include "naughty_differential_node_var.hpp"
#include <string>

namespace naughty_differential
{

node_var::node_var(std::string id)
    :
        node_base({}),
        m_id(id),
        m_char_set("abcdefghijklmnopqrstuvwxyz")
{

}

std::shared_ptr< node_base> node_var::differential(std::string variable)
{
    if (variable == m_id)
    {
        return std::make_shared<node_num>(1);
    }
    return std::make_shared<node_num>(0);
}

enum node_type node_var::get_node_type()
{
    return node_type_val;
}

std::string node_var::serialize()
{
    return {};
}

std::string node_var::to_string() const
{
    return m_id;
}

std::shared_ptr<node_base> node_var::clone()
{
    return std::make_shared<node_var>(m_id);
}

double node_var::get_value(std::map<std::string, double> val_value_map)
{
    std::map<std::string, double>::const_iterator iter = val_value_map.find(m_id);

    if (iter == val_value_map.cend())
    {
        assert(0);
        throw std::exception();
    }

    return iter->second;
}

std::string node_var::identity_string() const
{
    return std::string("{") + m_id + "}";
}

}
